package com.chen.admin.service;


import com.chen.admin.common.Result;
import com.chen.admin.entity.User;
import com.chen.admin.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {


    @Autowired
    private UserMapper userMapper;

    public List<User> getUserPage() {

        List<User> userPage = userMapper.getUserPage();
        return userPage;
    }

    public Result deleteUserById(Integer id) {
        int count = userMapper.deleteById(id);
        if (count == 0) {
            return Result.error("400", "删除失败");
        }
        return Result.success("删除成功");

    }

    public Result addUser(User user) {
        int count = userMapper.addUser(user);
        if (count == 0) {
            return Result.error("400", "添加失败");
        }
        return Result.success("添加成功");
    }

    public User getUserByName(String userName) {

        User userInfo = userMapper.getUserByName(userName);
        return userInfo;

    }

    public Result editUserInfo(User user,Integer id) {

       int count= userMapper.editUserInfo(user,id);
       if(count==0){
           return Result.error("400","编辑失败");
       }
       return Result.success("编辑成功");



    }
}
